package com.apply.config.utils;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author tianp
 */
public class CookieUtils {
    public CookieUtils() {
    }

    public static String getValueFromRequest(HttpServletRequest request, String name) {
        Validate.notNull(request, "request cannot be null", new Object[0]);
        Cookie[] cookies = request.getCookies();
        if (cookies != null && StringUtils.isNotEmpty(name)) {
            Cookie[] arr$ = cookies;
            int len$ = cookies.length;

            for (int i$ = 0; i$ < len$; ++i$) {
                Cookie cookie = arr$[i$];
                if (name.equals(cookie.getName())) {
                    return cookie.getValue();
                }
            }
        }

        return null;
    }
}
